package org.phalanx.client.menus;

import java.awt.Color;

import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;

import org.phalanx.client.mapeditor.PhalanxMapEditorPanel;

public class MapMenuPopUp extends JPopupMenu {
	JMenuItem newMap;
	JMenuItem exit;
	JMenuItem open;
	JMenuItem save;
	JMenuItem saveAs;
	JMenuItem goToMainMenu;
	JPanel masterPanel;
	
	MapMenuAction mapActions;
	
	public MapMenuPopUp(JPanel masterPanel){
		this.masterPanel = masterPanel;
		initializeMenu();
	}
	
	private void initializeMenu(){
		this.setBackground(Color.white);
		this.setForeground(Color.black);
		configureMenuItems();
		
		this.add(newMap);
		this.add(open);
		this.addSeparator();
		this.add(save);
		this.add(saveAs);
		this.addSeparator();
		this.add(goToMainMenu);
		this.add(exit);
		
		this.pack();
	}
	
	private void configureMenuItems(){
		PhalanxMapEditorPanel pe = (PhalanxMapEditorPanel)masterPanel;
		mapActions = new MapMenuAction(pe);

		newMap = createDefaultMenuItem();
		newMap.setText("New");
		newMap.setName("NewMap");
	
		
		open = createDefaultMenuItem();
		open.setText("Open...");
		open.setName("OpenMap");
		
		save = createDefaultMenuItem();
		save.setText("Save");
		save.setName("SaveMap");
		
		saveAs = createDefaultMenuItem();
		saveAs.setText("Save As...");
		saveAs.setName("SaveMapAs");
		
		goToMainMenu = createDefaultMenuItem();
		goToMainMenu.setText("Go To Main Menu");
		goToMainMenu.setName("goToMainMenu");
		
		exit = createDefaultMenuItem();
		exit.setText("Exit");
		exit.setName("ExitEditor");
		
		goToMainMenu.addActionListener(mapActions);
		open.addActionListener(mapActions);
		save.addActionListener(mapActions);
		saveAs.addActionListener(mapActions);
		newMap.addActionListener(mapActions);
		exit.addActionListener(mapActions);
	}
	
	private JMenuItem createDefaultMenuItem(){
		JMenuItem tempMenuItem = new JMenuItem();
		tempMenuItem.setForeground(Color.black);
		tempMenuItem.setBackground(Color.white);
		
		return tempMenuItem;
	}
	
}
